package com.heima.example1;

import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;
import java.util.Date;
import java.util.Scanner;
import java.util.concurrent.TimeUnit;

public class Client {
    public static void main(String[] args) throws Exception {

        Socket socket = new Socket("localhost", 8888);

        OutputStream outputStream = socket.getOutputStream();
        InputStream inputStream = socket.getInputStream();

        Scanner scanner = new Scanner(System.in);

        while (true) {
            System.out.println("请输入要发给服务端的信息:");
            String input = scanner.nextLine();

            if ("886".equals(input)) {
                System.out.println("马上进行shutdown-----"+new Date().getTime());
                socket.shutdownOutput();
                TimeUnit.SECONDS.sleep(3);
                break;
            }

            input = input + System.getProperty("line.separator");
            outputStream.write(input.getBytes());
        }

        socket.close();
    }
}
